package cn.lyx.xiaohoshu.auth.controller;

import cn.lyx.framework.biz.operationlog.aspect.ApiOperationLog;
import cn.lyx.framework.common.response.Response;
import cn.lyx.framework.context.holder.LoginUserContextHolder;
import cn.lyx.xiaohoshu.auth.model.vo.user.UpdateUserPasswordReqVO;
import cn.lyx.xiaohoshu.auth.model.vo.user.UserLoginReqVO;
import cn.lyx.xiaohoshu.auth.service.UserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author by lyx
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Resource
    private UserService userService;
    @PostMapping("/login")
    @ApiOperationLog(description = "用户登录")
    public Response<String> loginAndRegister(@RequestBody @Validated UserLoginReqVO userLoginReqVO) {
        return userService.loginAndRegister(userLoginReqVO);
    }

    @PostMapping("/logout")
    @ApiOperationLog(description = "用户退出")
    public Response<?> logout() {
        return userService.logout();
    }

    @PostMapping("/password/update")
    @ApiOperationLog(description = "修改密码")
    public Response<?> updateUserPassword(@RequestBody @Validated UpdateUserPasswordReqVO updateUserPasswordReqVO) {
        return userService.updateUserPassword(updateUserPasswordReqVO);
    }
}
